package com.liachen.common.util;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;

import java.io.File;
import java.util.Map;
@Slf4j
public class ToolsUtil {
    public static final OkHttpClient client = new OkHttpClient().newBuilder().build();

    public static Map<String, String> getCookie(String cookieStr) {
        String[] cookieStrs = cookieStr.split(";");
        Map<String, String> cookieMap = Maps.newHashMap();
        for (String cookie : cookieStrs) {
            cookieMap.put(cookie.split("=")[0], cookie.split("=")[1]);
        }
        return cookieMap;
    }

    public static OkHttpClient getClient() {
        return client;
    }

    /**
     * 创建文件上传路径
     * @param path
     * @return
     */
    public static boolean mkdir(String path) {
        File fd;
        try {
            fd = new File(path);
            if (!fd.exists()) {
                fd.mkdirs();
                return false;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            return true;
        }
    }
}
